
<#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
    
        <div class="wrap_search">
				        
							<input type="hidden" name="key" id="key" value="${key!''}"/>
			
        </div>
        <div style="text-align: left; margin:6px;">
        	<!--  
            -->
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
            
        </div>
    </div>
    

<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	//fitColumns:true,
    	striped:true,
    	multiSort:true,
    	singleSelect: false,
		ctrlSelect : true,
        queryParams: zcurdGetParam(),
        nowrap:false,
        onDblClickRow:function(index, row){dbClickShow(row.id);},
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'code', title: '编号', width:120, align:'center'}
	           	 ,{field:'name', title: '名称', width:200, align:'center'}
	           	 ,{field:'remark', title: '备注', width:500, align:'center'}
	           	 
	           	 <#if havaOrderNum>
	           	 ,{field:'orderNum', title: '排序号', width:80, align:'center'}
	           	 </#if>
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};


var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.datagrid(dgOptions); //绘制数据表格
	autoAddClear(); //为各组件自动填加‘清除’功能（组件需要增加 addClear属性 ）
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add() {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.datagrid("load");
	}
	top.openWindow("增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '480x305'});
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	//top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id + "&" + $.param(initPara), {size: '480x236'});
	editData(id);
}

//双击打开查看
function editData(id) {
	top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id + "&" + $.param(initPara), {size: '480x305'});
}

//删除
function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete")+ "?" + $.param(initPara), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.datagrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}


//详情
function detail() {
	var rowsSel = datagrid.datagrid("getChecked");
	if(rowsSel.length != 1) {
		showWarnMsg("请选【一条】数据！");
		return;
	}
	var id = rowsSel[0].id;
	dbClickShow(id);
}

//双击打开查看
function dbClickShow(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id + "&" + $.param(initPara), {size: '480x300'});
}


</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
